package shiro.controller;

import org.apache.shiro.authz.annotation.RequiresGuest;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import shiro.CurrentUser;
import shiro.JwtUtil;
import shiro.R;

import javax.servlet.http.HttpSession;

/**
 * @author lzh
 * @description
 * @date 2021/2/13
 */
@RestController
public class LoginController {
    @GetMapping("/login")
    public R login(String username,
                   String password) {
        CurrentUser user = new CurrentUser();
//        实际应用应从数据库中查询数据去设置
        user.setUsername(username);
        user.setRoleId(1);
        user.setUserId(1L);
        String token = JwtUtil.genToken(user);
        return R.succ(token);
    }

    @GetMapping("/")
    public R index() {
        return R.succ();
    }

    @GetMapping("/admin")
    @RequiresRoles("admin")
    public R admin() {
        return R.succ();
    }

    @GetMapping("/admin2")
    @RequiresRoles("admin2")
    public R admin2() {
        return R.succ();
    }
}
